from networkFramework import *
from dataStruct import snapshotStruct as sStruct
from framework import *
import time

def main():
    
    configData = getSSConfig()
    
    if len(sys.argv) == 3:
        host = sys.argv[1]
        port = int(sys.argv[2])
    else:
        host = configData['host']
        port = configData['port']

    book = initFakeBook()
    print book
    print len(book)
    
    timer = time.time() + 5
    bookObj = sStruct()
    buffSize = bookObj.buffSize
    bUDPConn = senderUDPConn(host, port)    
    bookObj.bufferValues(book)
    
    bUDPConn.sendData(bookObj.buffer.raw)   

    while True:
        if timer < time.time():    
            print time.time()
            bookObj.bufferValues(book)
            bUDPConn.sendData(bookObj.buffer.raw)
    
            bookDict = bookListToDict(bookObj.getValues())
            print "got book values of: " 
            print bookDict
            
            timer = time.time() + 5   
          
    bUDPConn.close()

if __name__ == "__main__":
    main()